package oj;

public class LC154 {
    public int findMin(int[] nums) {
        if(nums.length==1) return nums[0];
        int low=0;
        int high=nums.length-1;
        int mid=0;
        while(nums[low]>=nums[high]){
            if(high-low==1){
                mid=high;
                break;
            }
            mid=(high-low)/2+low;
            if(nums[low]==nums[high] && nums[mid]==nums[low])
                return min(nums,low,high);
            if(nums[mid]>=nums[low]){
                low=mid;
            }else if(nums[mid]<=nums[high]){
                high=mid;
            }
        }
        return nums[mid];
    }
    private int min(int[] nums,int low,int high){
        int result=nums[low];
        for(int i=low;i<=high;i++){
            if(nums[i]<result)
                result=nums[i];
        }
        return result;
    }
}
